Lab 17

Advanced Plotting

CS211 Lab Policy:

Instructions:

You will create one MATLAB program named Lab17 in file Lab17.m for this lab.  Perform the tasks described below to generate graphs that present information about the 2007 Pikes Peak Marathon. The data you will use comes from http://www.pikespeakmarathon.org/results.htm. The original data has been modified to make this lab easier to program.

  1. Begin your program by clearing the command window and displaying your name and "Lab 17".
  1. Save the file PikesPeakMarathon2007.txt to your current MATLAB working directory.
     
  2. Use the assignment statement below to read the race data from a file into eleven (11) distinct column vectors.

    [Overall_position Age_position Age_total Name Age Gender Town State Ascent Descent Total] ...
       = textread('PikesPeakMarathon2007.txt', '%d %d%*c%d %24c %d %c %15c %2c %7c %7c %7c');


    Do not attempt to understand this textread() command at this time. We will study how to read data from a file later in the semester.

    The column vectors that are created by the statement above are called "parallel arrays" because the data on row j of one array is related to the data on the jth row of all the other arrays. The arrays hold the following information:
     
    Row vector Description Size (Type)
    Overall_position The runner's finishing place (e.g., 1st, 2nd, 3rd, etc.) 882x1 (double)
    Age_position The runner's finishing place in their age category 882x1 (double)
    Age_total The total number of runners in this runner's age category 882x1 (double)
    Name The runner's name 882x24 (char)
    Age The runner's age 882x1 (double)
    Gender The runner's gender 882x1 (char)
    Town The runner's home town 882x7 (char)
    State The runner's home state (or country) 882x2 (char)
    Ascent The time it took for the runner to get to the top of Pikes Peak 882x7 (char)
    Descent The time it took for the runner to get down from the top of Pikes Peak 882x7 (char)
    Total The total race time for the runner 882x7 (char)

     

  3. Test the MATLAB statement from step 3 in the command prompt before using it in your program.  If you get an error message saying that the file was not found, type dir (for directory) at the command prompt to see if you properly placed the file in MATLAB's current working directory.  Make sure you are able to read the data from the file before proceeding. You may want to examine the contents of some of the vectors to get familiar with the data.
     
  4. Add code to count the number of males and females in the race. (Remember that comparisons work on arrays and produce a Boolean array as a result. And you can use the sum() function to count the number of true values in a Boolean vector.)
     
  5. Create a pie chart that shows the percentage of male and female runners. Include an appropriate graph title and legend. Your graph should look something like the example below (the following is from 2005 data).

               
     
  6. Add the following lines to your code. In addition, add these lines after every graph produced below so that you can see each individual graph.

    % wait for user to press enter, then close the figure window

    Wait = input('Press enter to continue.', 's');
    close()

     
  7. Add code to count the number of runners in each of the age groups listed below. (If you use array comparisons, they must be combined with the single logical operators (& and |), not (&& and ||)). Include an appropriate graph title and legend. Your graph should look something like the example below (the following is from 2005 data).
     
  8. Add code to show the distribution of runners based on their ages. Use a bin centered at the middle of each age category (i.e., 15, 25, 35, etc.). Include an appropriate graph title and axis labels. Your graph should look something like the example below (the following is from 2005 data).
     
               
     
  9. Add code to show a comparison of the number of runners from Arkansas (AR), Colorado (CO), Texas (TX), and New Mexico (NM). Use the strmatch('target', string_vector) function to find matching states. Include an appropriate graph title and bar labels. Your graph should look something like the example below (the following is from 2005 data).
     
               
     
  10. Add code to show a comparison between the age of runners and their finishing place in the race. Include an appropriate graph title and axis labels. Your graph should look something like the example below (the following is from 2005 data).
     
               
     
  11. If you have time, create a single figure window that includes 4 separate plots using the subplot() function. You can copy/paste the code from previous steps to create this figure. Your graph should look something like the example below (the following is from 2005 data).

Turn-in:

Submit your Lab17.m file.